package me.firstapp.manage.topic;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.common.json.ListObject;
import me.firstapp.common.json.SingleObject;
import me.firstapp.common.module.bbs.JsonSection;
import me.firstapp.common.module.bbs.JsonTopic;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.spi.bbs.SectionService;
import me.firstapp.spi.bbs.TopicService;

@Controller
@RequestMapping(value = "/topicManage")
public class TopicManagePage extends BaseManage {

	@Autowired
	private SectionService sectionService;

	@Autowired
	private TopicService topicService;

	@RequestMapping(value = "/topicList.html", method = RequestMethod.GET)
	public ModelAndView topicListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		ListObject<JsonSection> result = sectionService.findSectionList();
		modelMap.put("sections", result.getItems());
		return new ModelAndView("topic/topicList", modelMap);
	}

	@RequestMapping(value = "/topicDetail.html", method = RequestMethod.GET)
	public ModelAndView topicDetailView(Long topicId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		SingleObject<JsonTopic> result = topicService.findTopic(topicId);
		modelMap.put("topic", result.getObject());
		return new ModelAndView("topic/topicDetail", modelMap);
	}

}
